﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MetroFramework.Forms;
using System.Reflection;
using System.Windows.Forms;

namespace Managistics.Warehouse.Views.Base
{
    public class ViewBase : MetroForm, IView
    {

        public ViewBase() : base() 
        {
            
        }

        public new event Action Closed = delegate { };
               
        public void Open()
        {
            ShowDialog();
        }

        public void Open(IView view)
        {
            this.MdiParent = (Form)view;
            this.WindowState = FormWindowState.Maximized;
            this.Dock = DockStyle.Fill;
            this.Show();
            this.BringToFront();
        }



        public object GetValFromModel(object model, string property_name)
        {
            if (model == null) return null;
            var PropertyInfos = model.GetType().GetProperties();
            foreach (PropertyInfo pInfo in PropertyInfos)
            {
                if (pInfo.Name == property_name)
                {
                    return pInfo.GetValue(model, null);
                }

            }
            return null;
        }

    }
}
